package com.yf.springsession.controller;

import com.alibaba.fastjson.JSONObject;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.time.LocalDateTime;
/**
 * @ClassName   TestController
 * @Description 测试Spring Redis Session
 * @Author yf
 * @Date 2018/10/10 16:56
 * @Version 1.0
 */
@RestController
public class TestController {
    Log log= LogFactory.getLog(TestController.class);

    @RequestMapping("/session/test")
    public String set(HttpServletRequest request) {
        HttpSession session=request.getSession();
        String sessionId=session.getId();
        //设置session中内容
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("userId",System.currentTimeMillis());
        jsonObject.put("age", LocalDateTime.now().getMinute());
        session.setAttribute(sessionId, jsonObject);
        return sessionId;
    }
}
